/****************************************************************************** ** Functions by Derrick Sobodash ** http://www.cinnamonpirate.com/ ** Submitted to ROM Hacking.net on July 3, 2006 ******************************************************************************/ /****************************************************************************** ** apply_fireflower() ******************************************************************************* ** syntax: void apply_fireflower(string fire_file, string bin_file) ******************************************************************************* ** Applies a FireFlower Patch Format file. FireFlower is a popular format ** for NeoGeo graphic and color hacks created by Kuma (kuma_yeb@d1.dion.ne.jp) ** in 2000. Also able to apply console output generated by Microsoft ** File Compare (only when using the /b Binary Compare flag). ******************************************************************************/ function apply_fireflower($fire_file, $bin_file) { // Make sure the input is all valid if(!file_exists($fire_file)) die("Error: apply_fireflower(): Unable to open $fire_file\r\n\r\n"); if(!file_exists($bin_file)) die("Error: apply_fireflower(): Unable to open $bin_file\r\n\r\n"); // Open the patch file as a stream $fire = fopen($fire_file, "rb"); // Open the binary file in read/write mode $fa = fopen($bin_file, "r+b"); while(!feof($fire)) { $buffer = trim(fgets($fire, 1024)); if(strlen($buffer) == 15) { $flags = explode(" ", $buffer); if(count($flags) == 3) { $offset = hexdec(substr($flags[0], 0, 8)); $src_byte = hexdec($flags[1]); $mod_byte = hexdec($flags[2]); if(is_int($offset) && is_int($src_byte) && is_int($mod_byte)) { fseek($fa, $offset, SEEK_SET); $cur_byte = ord(fgetc($fa)); fseek($fa, $offset, SEEK_SET); if($cur_byte == $src_byte) fputs($fa, chr($mod_byte)); else if($cur_byte == $mod_byte) fputs($fa, chr($src_byte)); } else echo "$buffer\r\n"; } else echo "$buffer\r\n"; } else echo "$buffer\r\n"; } fclose($fa); fclose($fire); }